package drds.global_transaction.image.image_praser;

import drds.global_transaction.image.Image;
import drds.global_transaction.image.UndoLog;
import net.sf.jsqlparser.JSQLParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;

public class ShareLockImagePraser extends AbstractImagePraser
{

    static final Logger logger = LoggerFactory.getLogger(ShareLockImagePraser.class);

    ShareLockImagePraser(String orginSql, UndoLog undoLog)
    {
        //SqlpraserUtils解析不了lock
        this.originalSql = orginSql.substring(0, orginSql.toLowerCase().indexOf("lock"));
        this.undoLog = undoLog;
    }

    @Override
    public String getTableName() throws JSQLParserException, SQLException
    {
        return SqlPraser.selectSentenceTableName(originalSql);
    }

    @Override
    public String getWhereCondition() throws JSQLParserException
    {
        return SqlPraser.selectSentenceWhereCondition(originalSql);
    }

    @Override
    public Image generateBeforeImage() throws JSQLParserException, SQLException
    {
        return getImage();

    }

    @Override
    public Image generateAfterImage()
    {
        return null;
    }


    @Override
    public String getBeforeOrAfterImageSql() throws JSQLParserException
    {
        return imageSql;
    }

}
